package demo11.gumballstatewinner;

/**
 * 正在贩卖状态
 * */
public class SoldState implements State {
	 GumballMachine gumballMachine;
	 
	    public SoldState(GumballMachine gumballMachine) {
	        this.gumballMachine = gumballMachine;
	    }
	       
		@Override
		public void insertQuarter() {
			System.out.println("请稍等，我们已经给你一个口香糖");
		}
	 
		@Override
		public void ejectQuarter() {
			System.out.println("对不起，你已经转动曲柄了。");
		}
	 
		@Override
		public void turnCrank() {
			System.out.println("转了两圈不会让你另一个口香糖!");
		}
	 
		@Override
		public void dispense() {
			gumballMachine.releaseBall();
			if (gumballMachine.getCount() > 0) {
				gumballMachine.setState(gumballMachine.getNoQuarterState());
			} else {
				System.out.println("正在出糖果!");
				gumballMachine.setState(gumballMachine.getSoldOutState());
			}
		}
		
		@Override
		public void refill() { }
	 
		@Override
		public String toString() {
			return "分配一个口香糖";
		}
}
